package com.bingo.users.action;

import ibatis.Users;

import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.ParameterAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.bingo.facade.InewsFacade;
import com.bingo.facade.IusersFacade;
import com.googlecode.jsonplugin.annotations.JSON;

public class MakeUsers implements SessionAware, RequestAware, ParameterAware 
{
	private Map request;
	private Map session;
	private Map parameters;
	public Map getRequest() {
		return request;
	}
	public void setRequest(Map request) {
		this.request = request;
	}
	public Map getSession() {
		return session;
	}
	public void setSession(Map session) {
		this.session = session;
	}
	public Map getParameters() {
		return parameters;
	}
	public void setParameters(Map parameters) {
		this.parameters = parameters;
	}
	
	private IusersFacade usersFacade;
	@JSON(serialize=false)
	public IusersFacade getUsersFacade() {
		return usersFacade;
	}
	public void setUsersFacade(IusersFacade usersFacade) {
		this.usersFacade = usersFacade;
	}
	
	private Integer page;
	private Integer total;
	
	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}
	
	private Users users;
	
	public Users getUsers() {
		return users;
	}
	public void setUsers(Users users) {
		this.users = users;
	}
	public String getAllUser()
	{
		try {
			System.out.println("getAllUsers");
			List<Users> list=this.getUsersFacade().getAllUsers();
			request.put("userList",list);
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
		return "success";
	}
	
	public String getUserById()
	{
		try {
			System.out.println("getUserById   .....");
			System.out.println(parameters.get("id"));
			users=usersFacade.getUserById(0);
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
		return "success";
	}
	
	public String getUserByName()
	{
		try {
			System.out.println("getUserByName   .....");
			System.out.println(parameters.size());
			Iterator it=parameters.keySet().iterator();
			while(it.hasNext())
			{
				String keyValue=(String)it.next();
				System.out.println("keySet:"+keyValue);
				System.out.println(parameters.get(keyValue));
			}
			System.out.println("letter_pressed:"+parameters.get("letter_pressed").toString());
			users=usersFacade.getUserByName((String)parameters.get("name"));
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
		return "success";
	}
}
